package org.ChrisRiffleSoftware.WhatIfJesusIsGod.ChuckNorrisJoker;

import android.graphics.drawable.Drawable;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 
 * Controls the visual interface.  Project has taken the approach 
 * of manipulating the view with java source code instead of using 
 * xml files
 * 
 * @author RIF
 * 
 */
public class ChuckViewController {

	
	// *************************************************************************
	// *************************************************************************
	// 					members
	// *************************************************************************
	// *************************************************************************

	/*
	 * Var to maintain a reference to the activity(Android specific) 
	 * entry level class object which will be used in a couple places 
	 * by component view widgets created by this controller
	 */
	private ChuckNorrisJokerActivity chuckJokerActivity;
	
	private LinearLayout linLayout;

	private Button submitButton;

	private TextView jokeTxtView;

	private ImageView chucksHeadPictureView;
	
	private CheckBox soundToggleCheckBox;

	
	// *************************************************************************
	// *************************************************************************
	// 								constructors
	// *************************************************************************
	// *************************************************************************

	
	/**
	 * 
	 * Constructor saves a reference to the Android-specific application 
	 * entry point class
	 * 
	 * @param pActivity 
	 * 			The first class loaded by any Android application
	 */
	public ChuckViewController(ChuckNorrisJokerActivity pActivity) {
		
		chuckJokerActivity = pActivity;
	}
	
	// *************************************************************************
	// *************************************************************************
	// 								methods
	// *************************************************************************
	// *************************************************************************
	
	
	/**
	 * Gets the checkbox which allows the user to toggle between 
	 * hearing the jokes audibly or not(silent)
	 * 
	 * @return
	 * 		Sound toggle checkbox
	 */
	public CheckBox getSoundToggleCheckBox(){
		
		if(soundToggleCheckBox == null){
			
			soundToggleCheckBox = new CheckBox(chuckJokerActivity);
			soundToggleCheckBox.setText("Sound");
		}
		return soundToggleCheckBox;
	}

	
	/**
	 * getViewLayout
	 * 
	 * @return
	 * 		ViewLayout
	 */
	LinearLayout getViewLayout() {
		
		if (linLayout == null) {
			
			linLayout = new LinearLayout(chuckJokerActivity);
			linLayout.setOrientation(LinearLayout.VERTICAL);
			linLayout.addView(getChucksHeadPictureView());
			linLayout.addView(getSubmitButton());
			linLayout.addView(getSoundToggleCheckBox());
			linLayout.addView(getJokeTxtView());
		}
		return linLayout;
	}

	
	
	/**
	 * getNorisPicView
	 * 
	 * @return
	 */
	private ImageView getChucksHeadPictureView() {
		
		if (chucksHeadPictureView == null) {

			Drawable d = chuckJokerActivity.getResources().getDrawable(
					R.drawable.chuck_norris_215x184png);
			
			chucksHeadPictureView = new ImageView(chuckJokerActivity);			
			chucksHeadPictureView.setImageDrawable(d);
		}
		return chucksHeadPictureView;
	}

	
	/**
	 * getSubmitButton
	 * 
	 * @return
	 */
	Button getSubmitButton() {
		
		if (submitButton == null) {
			
			submitButton = new Button(chuckJokerActivity);
			submitButton.setText("DANGER");
			submitButton.setOnClickListener(chuckJokerActivity);
		}
		return submitButton;
	}

	
	/**
	 * getJokeTxtView
	 * 
	 * @return
	 * 		JokeTxtView
	 */
	TextView getJokeTxtView() {
		
		if (jokeTxtView == null) {
			
			jokeTxtView = new TextView(chuckJokerActivity);
		}
		return jokeTxtView;
	}

}



